﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.ComponentModel;
using System.Windows.Data;
using System.Windows.Media.Imaging;

namespace PathConverterSample
{
    public partial class Page : UserControl
    {
        PropertiesHolder propHolder;


        public Page()
        {
            propHolder = new PropertiesHolder();

            InitializeComponent();

            this.DataContext = propHolder;


        }

        private void btnSubmit_Click(object sender, RoutedEventArgs e)
        {
            if (null != path.Data)
                if ((path.Data as PathGeometry).Figures.Count > 0)
                {
                    PathConverter.StringToPathGeometryConverter conv = new PathConverter.StringToPathGeometryConverter();
                    string pathText = (string)conv.ConvertBack(path.Data as PathGeometry/*, typeof(string), null, new System.Globalization.CultureInfo("en-us")*/);

                    if (null != pathText)
                        if (pathText.Length > 0)
                            tbPath.Text = pathText;
                }
        }

        public string pathText 
        { 
            get {return propHolder.pathText;}
            set { propHolder.pathText = value; } 
        }
    }

    public class PropertiesHolder : INotifyPropertyChanged
    {
        public string pathText
        {
            get { return _pathText; }
            set
            {
                _pathText = value;
                OnPropertyChanged("pathText");
            }
        }

        string _pathText = default(string);

        #region INotifyPropertyChanged Members

        public event PropertyChangedEventHandler PropertyChanged;

        public void OnPropertyChanged(string name)
        {
            if (PropertyChanged != null)
                PropertyChanged(this, new PropertyChangedEventArgs(name));
        }

        #endregion 
    }
}
